﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoemGame.Query.Dapper
{
    public class PlayerInGameQuery:IPlayerInGameQuery
    {
        private readonly IDbConnection connection;

        public PlayerInGameQuery(IDbConnection connection)
        {
            this.connection = connection;
        }
        public async Task<IEnumerable<PlayerInGameRes>> GetPlayersInGameByGameAsync(Guid gameId)
        {
            return await connection.GetListAsync<PlayerInGameView>("where GameId='" + gameId + "'"); ;
        }

        public async Task<IEnumerable<PlayerInGameRes>> GetPlayersInGameByPlayerAsync(Guid playerId)
        {
            return await connection.GetListAsync<PlayerInGameView>("where GameId='" + playerId + "'"); ;
        }

        public async Task<IEnumerable<PlayerInGameRes>> GetPlayersInGameByConditionAsync(string wherecondition)
        {
            return await connection.GetListAsync<PlayerInGameView>(wherecondition); 
        }

        public async Task<IEnumerable<PlayerInGameRes>> GetPagedPlayersInGameByConditionAsync(int pageindex, int pagesize, string wherecondition, string orderby)
        {
            return await connection.GetListPagedAsync<PlayerInGameView>(
                pageindex, pagesize, wherecondition, orderby); 
        }

        public async Task<long> GetPlayersInGameCountByConditionAsync(int pageindex, int pagesize, string wherecondition, string orderby)
        {
            return await connection.RecordCountAsync<PlayerInGameView>(wherecondition);
        }
    }
}
